package model.humanbody

import groovy.transform.CompileStatic
import model.agent.Agent
import model.agent.AgentInterface

/**
 *
 */
@CompileStatic
public class Organ extends Agent{

	public Organ(String name){
		this.name = name
	}

	//DSL用setter
	def propertyMissing(String name, int value) {setVarValue(name,value)}

	//DSL用getter
	def propertyMissing(String name) { getVarValue(name)}
	
	
	//重载subAgents系列方法，禁止读写子主体
	def throwNoSubAgentException() {
		throw new Exception("脏器\"${name}\"不包含子主体")
	}
	
	def void addSubAgent(AgentInterface agent){
		throwNoSubAgentException()
	}
	
	def void removeSubAgent(String name){
		throwNoSubAgentException()
	}
	
	public AgentInterface getSubAgent(String name){
		throwNoSubAgentException()
		return null
	}

	/**
	 * 输出本organ的json字符串
	 * @return
	 */
	/*	def toJson(){
	 String s = JsonOutput.toJson(new OrganBean(this)).toString()
	 return  app.UnicodeDecoder.decode1(s)
	 }
	 */	

	String toString(){
		String s = ""
		variables.each{key,value ->
			s += value.toString() +"\n"
		}
		return s
	}

}
